from flask import Flask,render_template,request
import requests
from bs4 import BeautifulSoup
import sqlite3

app = Flask(__name__)
#conn = sqlite3.connect()
#curor = conn.cursor()
@app.route('/')
def index():
    return render_template("index.html")

@app.route('/login') #装饰器，如果访问网站路径(‘/’)就触发函数
def login():
    user = 123
    return  "1"

@app.route('/data')
def GetData():
    url = 'http://example.com'
    header = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.41"
    }
    response = requests.get(url=url)
    html = response.text  # 拿到网页源码
    soup = BeautifulSoup(html, "")
    all_titles_id = soup.findAll("h2")
    print(all_titles_id)
    return requests.get(url).text

if __name__== '__main__':
    app.run()
